<?php
/**
 * 每天凌晨4：50执行
 * 门店wiki流量池
 */
ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\cache\store\StoreFlowPool;
use Biz\model\bigData\StoreGoodsTrafficPool;

$day = date("Ymd", strtotime("-1 day"));
$wiki_list = StoreGoodsTrafficPool::select(['store_id', 'wiki_id', 'store_pool', 'city_id', 'city_name'], ['day' => $day]);
if ($wiki_list && is_array($wiki_list)) {
    var_dump('开始更新:' . count($wiki_list));
    StoreFlowPool::delByKey(StoreFlowPool::WIKI_HIGH);
    StoreFlowPool::delByKey(StoreFlowPool::WIKI_MIDDLE);
    StoreFlowPool::delByKey(StoreFlowPool::WIKI_LOW);
    foreach ($wiki_list as $val) {
        addWiki($val);
    }
    var_dump('结束更新');
}

function addWiki($info)
{
    $keyType = '';
    switch ($info['store_pool']) {
        case "a":
            $keyType = StoreFlowPool::WIKI_HIGH;
            break;
        case "b":
            $keyType = StoreFlowPool::WIKI_MIDDLE;
            break;
        case "c":
            $keyType = StoreFlowPool::WIKI_LOW;
            break;
    }
    if ($keyType && $info['city_id'] && $info['city_name']) {
        $data = [
            'wiki_id' => $info['wiki_id'],
            'city_name' => $info['city_name'],
            'city_id' => (int)$info['city_id']
        ];
        var_dump('add store wiki flow pool', $data);
        StoreFlowPool::addByKey($keyType, json_encode($data));
    }
}








